<template>
  <div class="filter-container btn-box">
    <div v-if="showModal" class="mask">
      <!-- <img class="loading-image" src="../../image/loading.gif" alt="正在处理，请等待。。。">
      <span class="mask-text">处理中，请等待...</span>-->
    </div>
    <span v-if="showQuery">
      <span v-if="hiddText">
        <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" :placeholder="placeholder" v-model="inputValue">
        </el-input>
      </span>
      <el-button class="filter-item" type="primary" icon="search" @click="queryBtn" size="small">搜索</el-button>
    </span>
    <el-button v-for="(btn,index) in list" :key="index" v-if="permissions[btn.auth]" class="filter-item" style="margin-left: 10px;" :disabled="btn.ctr && disabled"
      @click="buttonClick(btn.name,btn.click,btn.confirm)" :type="btn.type" :icon="btn.icon" size="small">{{btn.name}}</el-button>
    <span v-if="showBack">
      <el-button class="filter-item" type="warning" size="small" @click="back">返回</el-button>
    </span>
    <span class="slot-item">
      <slot> </slot>
    </span>
  </div>
</template>
<script>
export default {
  name: 'buttons',
  data () {
    return {
      inputValue: '',
      showModal: false
    }
  },
  props: {
    showQuery: {
      type: Boolean,
      default: function () {
        return false
      }
    },
    hiddText: {
      type: Boolean,
      default: function () {
        return false
      }
    },
    showBack: {
      type: Boolean,
      default: function () {
        return false
      }
    },
    permissions: {
      type: Object,
      default: function () {
        return {}
      }
    },
    disabled: {
      type: Boolean,
      default: function () {
        return false
      }
    },
    placeholder: {
      type: String,
      default: function () {
        return "搜索内容"
      }
    },
    list: {
      type: Array,
      default: function () {
        return []
      }
    }
  },
  created () {

  },
  methods: {
    buttonClick (name, funName, confirm) {
      let _this = this
      if (confirm) {
        this.$confirm("操作：" + name + ", 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.showModal = true;
          try {
            this.$emit(funName)
          } catch (e) {
            this.showModal = false
          }
          setTimeout(function () {
            _this.showModal = false
          }, 500)
        });
      } else {
        this.$emit(funName)
      }
    },
    queryBtn () {
      this.$emit('query', this.inputValue)
    },
    back () {
      this.$router.go(-1)
    }
  }
}
</script>

<style lang="scss" scoped>
.btn-box {
  padding-top: 8px;
  padding-left: 8px;
  border: #ebeef5 1px solid;
  clear: both;
}
.mask {
  background-color: rgb(0, 0, 0);
  opacity: 0.3;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 9999;
}
.mask-text {
  text-align: center;
  color: #fff;
  width: 160px;
  height: 60px;
  margin: 300px auto;
  position: absolute;
  z-index: 9998;
}
.slot-item {
  margin-bottom: 8px;
  display: inline-block;
  vertical-align: middle;
}
</style>
